Human activities are responsible for increase of CO2 which in turn shows bad effects such as global warming, cancer in species, increase of sea level and extinction of species leading to imbalance in food chain etc. In this paper, we have inferred from this dataset and made some insights that can be helpful to conserve the life on the earth.
import pandas as pd
import numpy as np
from matplotlib import animation
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from matplotlib import animation
import plotly.express as px
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from IPython.display import display
import ipywidgets as widgets
import plotly.graph_objects as go
import warnings
warnings.filterwarnings('ignore')
parent_db = pd.read_csv("./data/owid-co2-data.csv")
temperature_db = pd.read_csv("./data/annual_csv.csv")
sea_db = pd.read_csv("./data/csiro_recons_gmsl_yr_2015_csv.csv")
def clean_df(db):
non_countries = ['World','Asia','Asia (excl. China & India)','North America','Europe','North America (excl. USA)','EU-27','EU-28','Europe (excl. EU-27)','Europe (excl. EU-28)','International transport','Kuwaiti Oil Fires','Africa']
for place in non_countries:
db = db[db.country != place]
return db
db = clean_df(parent_db)
world_data = parent_db[parent_db.country == "World"]
all_countries = db['country'].unique()
all_columns = db.columns
countries_list = ["United States","China","Russia","India"]
co2_types = ["co2","coal_co2",'cement_co2','gas_co2','oil_co2','trade_co2','methane','nitrous_oxide','other_industry_co2']
energies = ["primary_energy_consumption" ,"energy_per_capita" ,"energy_per_gdp"]
top_countries = ["China", "United States", "India", "Russia"]
num_countries = len(all_countries)
world_data_co2s = world_data[["year","country"]+co2_types]
fig = px.line(world_data_co2s, x="year", y=co2_types,labels={
"value": "CO2 (Million tonnes)"},template="plotly_dark")
fig.show()
GDP of the United States, China, India, and Russia decreased from 3.074, 2.925, 1.557, and 5.446 in 1980 to 1.486, 2.087, 1.105, 2.406 in 2016. The energy per capita is another important attribute which is used to determine the energy consumed by the poplartion in that country. The top five countries which has the highest energy per capita are Qatar, United Arabian Emirates, Bahrain, Island, and Singapore with 225MWh, 158MWh, 151MWh, 118MWh and 114MWh respectively.As time progressed, with advancement of technology and better energy sources, the top energy consuming countries GDP diverted away from its energy consumption.
The correlation factor between change in GDP and increase in CO2 is 0.971, which is very high. It simply indicates that change in GDP and increase in CO2 is almost in a linear relationship. However, some countries like Russia, the United Kingdom, Germany, and France increased their GDP with low correlation constants such as 0.24, 0.63, 0.74, and 0.8, respectively. It shows us that fueling the GDP growth via carbon emission is unnecessary for development. Those Countries that rely on CO2 emissions for their GDP growth must adapt and follow the methods currently used by the countries for increasing their GDP without damaging the environment.
country_co2_gdp_corr = db.groupby("country")["co2"].corr(db["gdp"]).to_frame().reset_index()
country_co2_gdp_corr["gdp"] = db[db.year == 2018][["year","country","gdp"]]["gdp"].values
country_co2_gdp_corr = country_co2_gdp_corr.dropna()
country_co2_gdp_corr = country_co2_gdp_corr.sort_values(by = ["gdp"],ascending = False)
temp_df = country_co2_gdp_corr.head(20)
fig = px.scatter_3d(temp_df, x='country', y='co2', z='gdp',
color='country', labels={
"co2": "correlation factor",
"gdp": "GDP"},
template="plotly_dark")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
world_past_1900 = world_data_co2s[world_data_co2s.year >= 1900]
co2_type = "co2"
X = world_past_1900["year"].values.reshape(-1,1)
X_new = np.append(X,np.array(list(range(2020,2100))).reshape(-1,1)).reshape(-1,1)
Y = world_past_1900[co2_type].values.reshape(-1,1)
linear_regressor = LinearRegression()
linear_regressor.fit(X, Y)
Y_pred = linear_regressor.predict(X_new)
d = {'year':[],'co2':[]}
for x in X_new:
d['year'].append(x[0])
for y in Y_pred:
d['co2'].append(y[0])
xx = []
for i in X:
xx.append(i[0])
yy = []
for i in Y:
yy.append(i[0])
tt_df = pd.DataFrame({'year':xx,'co2':yy})
df = pd.DataFrame.from_dict(d)
fig = go.Figure()
fig.update_layout(
title={
'text': "CO2 emmision prediction for the next 100 years"
},template="plotly_dark")
fig.add_scatter( x=df['year'], y=df['co2'],name = "Predicted")
fig.add_scatter(x=tt_df["year"],y=tt_df["co2"],name = "CO2 emmision")
fig.show()
The total amount of CO2 emitted by all the countries over the past 250 years is 1696314 million tonnes. If this trend continues, by 2100, the CO2 emission will reach 55K million tonnes. Another factor related to the CO2 emissions is the world population, as it directly increases the energy demand. The world's population increased from 745 million in 1750 to 7.8 billion in 2020. The average primary energy consumption over the past 50 years is 24241, 17794, 4308, and 8870 in the United States of America, China, India, and Russia, respectively. The energy used per
world_energy = world_data[(world_data.year > 1980) & (world_data.year <2020)][["year","country"]+energies]
avg_energy = world_energy[world_energy.year>1980]["primary_energy_consumption"].values/num_countries
world_energy = world_energy.assign(avg_energy=avg_energy)
fig = px.bar(world_energy, x='year', y='avg_energy',labels={
"avg_energy": "Average primary energy consumption",
"year": "Year"},title = "Primary energy consumption of the world",template="plotly_dark")
fig.show()
From the year 2000 onwards 4 countries contributed to 50% of CO2 emissions these are China, United States, India, Russia. Out of these countries China and USA constitute to 41 % of CO2 emissions. They also hold the top CO2 emissions in cement, coal, oil, gas categories, with china taking the first place in CO2 emissions from cement and coal with an 10 year average of 753 and 7259 million tons are mainly divided into sub category like CO2 emission from Coal, oil and natural gas, cement and more.
Humans utilized these sources for their needs and they neglected the negative impact caused by them on the environment. In case of CO2 emissions from oil and gas United states of America takes first place with an 10 year average of 2217 and 1488 million tonnes respectively.
dff = db[(db.country == "Canada") | (db.country == "China") |(db.country == "United States") |(db.country == "Russia")|(db.country == "Japan")|(db.country == "India")][db.year > 2000] [["country","co2","year"]]
fig = px.bar(dff, x="country", y="co2", color="country",
animation_frame="year", animation_group="country",title="Top CO2 emmision countries over time",labels={
"co2": "CO2 emmision (million tonnes)",
"country": "Country"})
fig.show()
def co2_dist(year):
req_cols = ["country","year"]+co2_types
req_cols.remove("trade_co2")
co2_world_dist = world_data[world_data.year>1990][req_cols]
co2_world_dist[["coal_co2","gas_co2","cement_co2","oil_co2","methane","nitrous_oxide","other_industry_co2"]] = (co2_world_dist[["coal_co2","gas_co2","cement_co2","oil_co2","methane","nitrous_oxide","other_industry_co2"]].div(co2_world_dist.co2, axis=0))*100
co2_world_dist = co2_world_dist[co2_world_dist.year == year].transpose().reset_index()
co2_world_dist.columns = co2_world_dist.iloc[1]
co2_world_dist.rename(columns = {'year':'type_co2',year:'percentage'}, inplace = True)
co2_world_dist.drop([0,1,2], axis=0, inplace=True)
return co2_world_dist
From the pie charts in the code module, CO2 emissions from coal has been the highest contributing source in the overall CO2 emissions accounting for 40.7% of CO2 emissions in 2020. Furthermore, we can observe that due to industrial revolution the use of coal accelerated as it was the main energy source and is not showing any signs of slowing down anytime soon. It is noteworthy to point out that percentage of CO2 emission contributing to the overall global emissions has decreased from 96% in 1900 to 42% in 2020 which indicates that we are moving away from coal as our main source of energy.
fig = px.pie(co2_dist(2020), values='percentage',names = 'type_co2',title = "Distribution of overall CO2 emmision in 2020")
fig.show()
fig = px.pie(co2_dist(2000), values='percentage',names = 'type_co2',title = "Distribution of overall CO2 emmision in 2000")
fig.show()
print("cumulative emmision in the world in the past 250 years")
world_past_250 = world_data_co2s[(world_data_co2s.year >= 2000) & (world_data_co2s.year <= 2017)]
world_past_250[co2_types].sum(axis = 0)
cumulative emmision in the world in the past 250 years
co2 568553.140 coal_co2 228924.377 cement_co2 20766.537 gas_co2 106230.920 oil_co2 201801.842 trade_co2 0.000 methane 138267.990 nitrous_oxide 50599.240 other_industry_co2 4637.491 dtype: float64
In the year 2020, the amount of the CO2 in the world is 34.8 billion tonnes based purely on territorial emissions. About 100 years ago, CO2 emissions from all over the world was 3507 million tonnes which is 10% of the CO2 emission in 2020. The rate in which CO2 emissions increased in the late 19th century and early 20th century is extremely more. Notable years which contributed to this drastic increase are 1949 with 1922 percentage year on year.
d = {}
for year in range(2000,2018):
d[year] = world_past_250[world_past_250.year == year]["co2"].values[0]
li = list(d.values())
inc = (np.diff(li)/li[:-1])*100
i=0
_max = 0
_year = 0
strs = []
for year in range(2000,2017):
strs.append(str(round(inc[i],3))+"%")
_max = max(_max,inc[i])
if(_max == inc[i]):
_year = year
i+=1
print("Maximum increase in CO2 emmissions between 2000-2018 happend in {} with a {}% increase in gloabal CO2 emmision".format(_year,round(_max,3)))
Maximum increase in CO2 emmissions between 2000-2018 happend in 2009 with a 5.493% increase in gloabal CO2 emmision
During the past ten years, has the world woken up to the disturbing fact that it is suffocating in carbon emissions. Many countries have come forward to address this issue through agreements, policies, and resolutions. We noticed that the production of CO2 emissions did not decrease but rather increased over the past five years. Even though these resolutions are considered revolutionary in addressing the issue, they have had minimal effect in changing the direction in which the world is moving.
The climate change act was passed in the UK in 2008. It was the first country to take the initiative to set emission targets. The Paris agreement is a legally binding international treaty on climate change. The main goal of these acts is to reduce global warming by taking precautions. It came into force in the year 2016. There was a decrease of 1.25% in Global CO2 emissions from 2015 to 2016. India adopted a National Action Plan for Climate change(NAPCC) in 2008 related to climate change.
fig = go.Figure(data=[
go.Bar(x=world_past_250['year'].values, y=world_past_250['co2'].values,text = strs,textposition='outside')
])
fig.update_layout(
title="Change in CO2 emmsion over time",
xaxis_title="Global CO2 emmision in million tonnes",
yaxis_title="Year",template="plotly_dark"
)
fig.show()
geo_data = db[db.year>1980][["iso_code","country","year","co2"]].dropna()
fig = px.scatter_geo(geo_data, locations="iso_code", color="country",
hover_name="country", size="co2",
projection="natural earth", animation_frame="year", template="plotly_dark",title = "CO2 emmisions over time")
fig.show()
fig = px.scatter(sea_db, x="Time", y="GMSL", title="Global Mean Sea Level",labels={
"GMSL": "GMSL(mm)"},template="plotly_dark")
fig.show()
The Global temperature in 1880 was -0.1140C. Now, It is increased to 1.110C. Global warming results in a bad impact on melting glaciers which in turn increases sea level. In 1910 the global mean sea level crossed the zero mark and within a span of 10 years, it reached 65 mm. The effect of an increase in sea level can worsen the habitat of many organisms. It also puts many Oceania countries at risk.
These are the inferences that we made from the data. Using the inference that we made from the dataset, we conclude that we must come up with sophisticated methods to save Earth from Global warming.
df1 = pd.DataFrame(columns = ["Source","Year","Mean"])
r,c = df.shape
i = 0
j = 0
while i<r:
row = temperature_db.iloc[i]
df1.loc[j] = row
i = i+2
j = j+1
fig = px.scatter(df1, x="Year", y="Mean", title="Variation in Tempertaure over time",labels={
"Mean": "Mean temperature"},template="plotly_dark")
fig.show()